<template>
  <div id="ct0_download_box">
    <div id="ct0_download">
      <a href="javascript:;" id="ct0_download_enter" @click="go" data-sudaclick="homepage_download"></a>
      <a href="javascript:;" id="ct0_download_close" @click="close" data-sudaclick="homepage_download_close"></a>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
export default {
  data() {
    return {
    }
  },
  created() {
    var self = this;
    var dlwin = function() {
      var clientWidth = util.viewData().viewWidth;
      if (clientWidth >= maxW) {
        clientWidth = maxW;
        $('#ct0_download_box').hide();
      }
      var h = Math.floor(clientWidth * 12 / 75);
      $('#ct0_download').height(h);
      self.setPlaceHolder(h);
      var ew = Math.ceil(clientWidth * 153 / 750);
      var er = Math.floor(clientWidth * 95 / 750);
      $('#ct0_download_enter').css({
        'width': ew + 'px',
        'right': er + 'px'
      });
      var cw = Math.ceil(clientWidth * 75 / 750);
      $('#ct0_download_close').css({
        'width': cw + 'px'
      });
    }

    window.onresize = function() {
      dlwin();
    }
    this.$nextTick(() => {
      dlwin();
    })
  },
  methods: {
    setPlaceHolder(h) {
      if ($('#ct0_download_placeholder').length === 0) {
        $("body").append('<div id="ct0_download_placeholder" class="landhide"></div>')
      }
      $('#ct0_download_placeholder').height(h);
    },
    go() {
      //        var downloadUrl = 'http://lotto.sina.cn/ai/app/download/';
      let bv = window.browser.versions;
      if (bv.weixin || bv.qq) {
        location.href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.sina.lottery.gai';
      } else if (bv.ios || bv.iPhone || bv.iPad) {
        var ua = navigator.userAgent.toLowerCase();
        if (ua.match(/WeiBo/i) == 'weibo') {
          var $wb_tip = '';
          if ($("#wb_tip").length > 0) {
            $wb_tip = $("#wb_tip");
          } else {
            $wb_tip = $('<div class="wx_box" id="wb_tip"><div class="wx_tips"><img src="  http://n.sinaimg.cn/sports/lottpao/v120/wap/i/download/wb_tips.png" alt="weixin"></div></div>');
            $('body').append($wb_tip);
          }
          $wb_tip.show();
          $wb_tip.on("click", function() {
            $wb_tip.hide();
          })
          return;
        }
        // location.href = 'https://itunes.apple.com/cn/app/id1188191652';
        window['iOS_download'] = function() {
        };
        $.ajax({
          url: 'http://interface.sina.cn/sports/caitong/get_download_info.d.json?__platform__=iOS&channel=',
          dataType: 'jsonp',
          data: {},
          cache: false,
          jsonpCallback: 'iOS_download',
          type: 'get',
          success: function(data) {
            var result = data.result;
            if (result.status.code == 0) {
              util.aphoneDLink = result.data.latestVersionInfo.downloadAddr;
              util.openApp(util.schemeDLink, util.aphoneDLink);
            }
          }
        });
      } else {
        //android
        window['android_download'] = function() {
        };
        $.ajax({
          url: 'http://interface.sina.cn/sports/caitong/get_download_info.d.json?__platform__=android&channel=',
          dataType: 'jsonp',
          data: {},
          cache: false,
          jsonpCallback: 'android_download',
          type: 'get',
          success: function(data) {
            var result = data.result;
            if (result.status.code == 0) {
              util.aphoneDLink = result.data.latestVersionInfo.downloadAddr;
              util.openApp(util.schemeDLink, util.aphoneDLink);
            }
          }
        });
      }
    },
    close() {
      $('#ct0_download').hide();
    }
  }
};
</script>

<style lang="stylus" rel="stylesheet/stylus">
  .landscape
    #ct0_download_box,.landhide
      display: none   
  #ct0_download
    position: absolute
    position: fixed
    left: 0
    right: 0
    bottom: 0
    background: url(http://n.sinaimg.cn/sports/sina_lotto/lotto/wap/i/lotto_win.png) no-repeat
    background-size: 100% auto
    width: 100%
    z-index: 1002
    pointer-events: all
    #ct0_download_enter
      position: absolute
      right: 47px
      top: 0
      bottom: 0
      width: 76px
      cursor: pointer
    #ct0_download_close
      position: absolute
      right: 0
      top: 0
      bottom: 0
      width: 38px
      cursor: pointer
</style>